//
// Created by YueChuan on 2023/4/13.
//

#include "address.h"

yuechuan::Logger::ptr g_logger = YUECHUAN_LOG_ROOT();


void test() {
    std::vector<yuechuan::Address::ptr> addrs;

    bool v = yuechuan::Address::Lookup(addrs, "www.baidu.com:http");
    if (!v) {
        YUECHUAN_LOG_ERROR(g_logger) << "lookup error";
        return;
    }
    for (size_t i = 0; i < addrs.size(); ++i) {
        YUECHUAN_LOG_INFO(g_logger) << i << " - " << addrs[i]->toString();
    }
}

void test_interaface() {
    std::multimap<std::string, std::pair<yuechuan::Address::ptr, uint32_t> > results;
    bool v = yuechuan::Address::GetInterfaceAddress(results, AF_INET6);
    if (!v) {
        YUECHUAN_LOG_ERROR(g_logger) << "GetInterface error";
        return;
    }
    for (auto &i: results) {
        YUECHUAN_LOG_INFO(g_logger) << i.first << " - " << i.second.first->toString() << " - " << i.second.second;
    }
    return;
}

void test_ipv4() {
    auto addr = yuechuan::IPAddress::Create("www.baidu.com");
    if (addr) {
        YUECHUAN_LOG_INFO(g_logger) << addr->toString();
    }
}

int main(int argc, char **argv) {
//    test();
//    test_interaface();
    test_ipv4();
    return 0;

}